<?php

namespace App\Models;

use App\Models\Admin\Level;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    public $table = 'product';

    protected $fillable = [
        'name', 'price', 'level_id', 'from', 'to', 'apple_id', 'original', 'input_1', 'input_2', 'input_3', 'minute'
    ];

    protected $appends = [
        'original',
        'price',
//        'days'
    ];

    public function level()
    {
        return $this->belongsTo(Level::class, 'level_id', 'id');
    }

    public function setPriceAttribute($value)
    {
        $this->attributes['price'] = intval($value * 100);
    }

    public function getPriceAttribute($key)
    {
        return $this->attributes['price'] / 100;
    }

    public function setOriginalAttribute($value)
    {
        $this->attributes['original'] = intval($value * 100);
    }

    public function getOriginalAttribute($key)
    {
        return $this->attributes['original'] / 100;
    }

//    public function getDaysAttribute($key)
//    {
//        $dtToronto   = Carbon::parse($this->attributes['from'] . '00:00:00');
//        $dtVancouver = Carbon::parse($this->attributes['to'] . '23:59:59');
//        return $dtVancouver->diffInDays($dtToronto);
//    }
}
